﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CCUiCMCCreateContinuousMFGFromCurveDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.CreateContinuousMFGFromCurve;

public class CCUiCMCCreateContinuousMFGFromCurveDlg : TxForm
{
  private const string _STRING_TABLE_LOCATION = "DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CMCStringTable";
  private ResourceManager _resourceManager;
  private CApCMCCreateContinuousMFGFromCurveEmsLogic _logic;
  private IContainer components;
  private TxObjGridCtrl txogMFGList;
  private TxButton btnBrowse;
  private Label lbl3DFile;
  private TextBox tb3DFile;
  private Button btnCancel;
  private Button btnOK;
  private Label lblAssignToPart;
  private TxObjEditBoxCtrl txebAssignToPart;
  private ComboBox cbPlanningType;
  private Label lblPlanningType;

  public CCUiCMCCreateContinuousMFGFromCurveDlg()
  {
    this.InitializeComponent();
    this._resourceManager = new ResourceManager("DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CMCStringTable", ((object) this).GetType().Assembly);
    this._logic = new CApCMCCreateContinuousMFGFromCurveEmsLogic(this.txogMFGList, this.txebAssignToPart, this.cbPlanningType, this.tb3DFile, (Button) this.btnBrowse, this.btnOK);
    this.btnBrowse.SetImage(TxImageManager.GetImageByKey("Options"), new Size());
    if (this.cbPlanningType.Items.Count <= 0)
      return;
    this.cbPlanningType.SelectedIndex = this._logic.GetPlanningTypeIndexFromRegistry((Form) this);
  }

  public virtual void OnInitTxForm()
  {
    // ISSUE: unable to decompile the method.
  }

  private void CCUiCMCCreateContinuousMFGFromCurveDlg_Load(object sender, EventArgs e)
  {
    this.InitializeMFGList();
    this._logic.AddCurvesToList(TxApplication.ActiveSelection.GetAllItems());
    this.tb3DFile.Text = TxApplication.Options.Continuous.Continuous3DFolder;
    this._logic.EnableOrDisableButtons();
  }

  private void InitializeMFGList()
  {
    TxGridColumnData txGridColumnData1 = new TxGridColumnData();
    TxGridColumnData txGridColumnData2 = new TxGridColumnData();
    string text1 = this._resourceManager.GetString("CMC_MfgListMfgNameColumnTitle");
    string text2 = this._resourceManager.GetString("CMC_MfgListCurveColumnTitle");
    using (Graphics graphics = ((Control) this).CreateGraphics())
    {
      TxGridColumnData txGridColumnData3 = txGridColumnData1;
      SizeF sizeF = graphics.MeasureString(text1, ((Control) this).Font);
      int num1 = Math.Max(150, Convert.ToInt32(sizeF.Width) + 20);
      txGridColumnData3.Width = num1;
      TxGridColumnData txGridColumnData4 = txGridColumnData2;
      sizeF = graphics.MeasureString(text2, ((Control) this).Font);
      int num2 = Math.Max(150, Convert.ToInt32(sizeF.Width) + 20);
      txGridColumnData4.Width = num2;
    }
    txGridColumnData1.Init(text1, (TxGridColumnType) 0);
    txGridColumnData2.Init(text2, (TxGridColumnType) 0);
    TxGridColumnDataCollection columnDataCollection = new TxGridColumnDataCollection();
    columnDataCollection.AddItem(txGridColumnData1);
    columnDataCollection.AddItem(txGridColumnData2);
    TxGridDescription txGridDescription = new TxGridDescription();
    txGridDescription.SetData(columnDataCollection, 1);
    this.txogMFGList.Init(txGridDescription);
    this._logic.EnableOrDisableButtons();
  }

  private void txogMFGList_Picked(object sender, TxObjGridCtrl_PickedEventArgs args)
  {
  }

  private void txogMFGList_ObjectInserted(object sender, TxObjGridCtrl_ObjectInsertedEventArgs args)
  {
    string uniqueCurveName = this.GetUniqueCurveName(args.Obj.Name, args.Row);
    this.txogMFGList.SetTextValue(args.Row, 0, uniqueCurveName);
    this._logic.EnableOrDisableButtons();
  }

  private void txogMFGList_DataChanged(object sender, TxObjGridCtrl_DataChangedEventArgs args)
  {
    this._logic.EnableOrDisableButtons();
  }

  private string GetUniqueCurveName(string name, int row)
  {
    if (name == "")
      name = this.cbPlanningType.Text;
    string key1 = name;
    Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
    for (int index = 0; index < this.txogMFGList.Count; ++index)
    {
      if (index != row)
      {
        string textValue = this.txogMFGList.GetTextValue(index, 0);
        if (!dictionary.ContainsKey(textValue))
          dictionary.Add(textValue, true);
      }
    }
    TxPhysicalRoot physicalRoot = TxApplication.ActiveDocument.PhysicalRoot;
    if (key1 != physicalRoot.GetUniqueDisplayName(key1) || dictionary.ContainsKey(key1))
    {
      char c = key1[key1.Length - 1];
      int num = 0;
      if (char.IsDigit(c))
      {
        num = (int) c - 48 /*0x30*/;
        key1 = key1.Remove(key1.Length - 1);
      }
      bool flag = false;
      do
      {
        ++num;
        string key2 = key1 + num.ToString();
        if (key2 == physicalRoot.GetUniqueDisplayName(key2) && !dictionary.ContainsKey(key2))
        {
          flag = true;
          key1 = key2;
        }
      }
      while (!flag);
    }
    return key1;
  }

  private void txebAssignToPart_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this._logic.EnableOrDisableButtons();
  }

  private void txebAssignToPart_TypeInvalid(object sender, EventArgs e)
  {
    this._logic.EnableOrDisableButtons();
  }

  private void txebAssignToPart_TypeValid(object sender, EventArgs e)
  {
    this._logic.EnableOrDisableButtons();
  }

  private void tb3DFile_TextChanged(object sender, EventArgs e)
  {
    this._logic.EnableOrDisableButtons();
  }

  private void btnOK_Click(object sender, EventArgs e)
  {
    this._logic.CreateMFGs(this.cbPlanningType.Text);
    this._logic.SetPlanningTypeInRegistry((Form) this);
    ((Form) this).Close();
  }

  private void btnCancel_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void btnBrowse_Click(object sender, EventArgs e)
  {
    TxApplication.Options.OpenDialog((TxOptions.TxDialogTab) 5);
    this.tb3DFile.Text = TxApplication.Options.Continuous.Continuous3DFolder;
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CCUiCMCCreateContinuousMFGFromCurveDlg));
    this.txogMFGList = new TxObjGridCtrl();
    this.btnBrowse = new TxButton();
    this.lbl3DFile = new Label();
    this.tb3DFile = new TextBox();
    this.btnCancel = new Button();
    this.btnOK = new Button();
    this.lblAssignToPart = new Label();
    this.txebAssignToPart = new TxObjEditBoxCtrl();
    this.cbPlanningType = new ComboBox();
    this.lblPlanningType = new Label();
    ((Control) this).SuspendLayout();
    ((UserControl) this.txogMFGList).BorderStyle = BorderStyle.FixedSingle;
    this.txogMFGList.ChangeGeneralSelection = false;
    this.txogMFGList.CurrentRow = -1;
    this.txogMFGList.EnableMultipleSelection = true;
    this.txogMFGList.EnableRecurringObjects = false;
    this.txogMFGList.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txogMFGList, "txogMFGList");
    ((Control) this.txogMFGList).Name = "txogMFGList";
    this.txogMFGList.PickLevel = (TxPickLevel) 2;
    this.txogMFGList.ReadOnly = false;
    this.txogMFGList.ValidatorType = (TxValidatorType) 1;
    this.txogMFGList.DataChanged += new TxObjGridCtrl_DataChangedEventHandler(this.txogMFGList_DataChanged);
    this.txogMFGList.ObjectInserted += new TxObjGridCtrl_ObjectInsertedEventHandler(this.txogMFGList_ObjectInserted);
    this.txogMFGList.Picked += new TxObjGridCtrl_PickedEventHandler(this.txogMFGList_Picked);
    ((ButtonBase) this.btnBrowse).Image = (Image) StringTable.Options;
    componentResourceManager.ApplyResources((object) this.btnBrowse, "btnBrowse");
    ((ButtonBase) this.btnBrowse).Image = (Image) StringTable.Options;
    ((Control) this.btnBrowse).Name = "btnBrowse";
    ((ButtonBase) this.btnBrowse).UseVisualStyleBackColor = true;
    ((Control) this.btnBrowse).Click += new EventHandler(this.btnBrowse_Click);
    componentResourceManager.ApplyResources((object) this.lbl3DFile, "lbl3DFile");
    this.lbl3DFile.Name = "lbl3DFile";
    componentResourceManager.ApplyResources((object) this.tb3DFile, "tb3DFile");
    this.tb3DFile.Name = "tb3DFile";
    this.tb3DFile.ReadOnly = true;
    this.tb3DFile.TextChanged += new EventHandler(this.tb3DFile_TextChanged);
    componentResourceManager.ApplyResources((object) this.btnCancel, "btnCancel");
    this.btnCancel.Name = "btnCancel";
    this.btnCancel.UseVisualStyleBackColor = true;
    this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
    componentResourceManager.ApplyResources((object) this.btnOK, "btnOK");
    this.btnOK.Name = "btnOK";
    this.btnOK.UseVisualStyleBackColor = true;
    this.btnOK.Click += new EventHandler(this.btnOK_Click);
    componentResourceManager.ApplyResources((object) this.lblAssignToPart, "lblAssignToPart");
    this.lblAssignToPart.Name = "lblAssignToPart";
    this.txebAssignToPart.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.txebAssignToPart.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txebAssignToPart, "txebAssignToPart");
    ((Control) this.txebAssignToPart).Name = "txebAssignToPart";
    this.txebAssignToPart.Object = (ITxObject) null;
    this.txebAssignToPart.PickAndClear = false;
    this.txebAssignToPart.PickLevel = (TxPickLevel) 1;
    this.txebAssignToPart.PickOnly = false;
    this.txebAssignToPart.ReadOnly = false;
    this.txebAssignToPart.ValidatorType = (TxValidatorType) 3;
    this.txebAssignToPart.TypeInvalid += new EventHandler(this.txebAssignToPart_TypeInvalid);
    this.txebAssignToPart.TypeValid += new EventHandler(this.txebAssignToPart_TypeValid);
    this.txebAssignToPart.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.txebAssignToPart_Picked);
    this.cbPlanningType.DropDownStyle = ComboBoxStyle.DropDownList;
    this.cbPlanningType.FormattingEnabled = true;
    componentResourceManager.ApplyResources((object) this.cbPlanningType, "cbPlanningType");
    this.cbPlanningType.Name = "cbPlanningType";
    componentResourceManager.ApplyResources((object) this.lblPlanningType, "lblPlanningType");
    this.lblPlanningType.Name = "lblPlanningType";
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Control) this).Controls.Add((Control) this.lblPlanningType);
    ((Control) this).Controls.Add((Control) this.cbPlanningType);
    ((Control) this).Controls.Add((Control) this.txebAssignToPart);
    ((Control) this).Controls.Add((Control) this.lblAssignToPart);
    ((Control) this).Controls.Add((Control) this.btnOK);
    ((Control) this).Controls.Add((Control) this.btnCancel);
    ((Control) this).Controls.Add((Control) this.btnBrowse);
    ((Control) this).Controls.Add((Control) this.lbl3DFile);
    ((Control) this).Controls.Add((Control) this.tb3DFile);
    ((Control) this).Controls.Add((Control) this.txogMFGList);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CCUiCMCCreateContinuousMFGFromCurveDlg);
    ((Form) this).Load += new EventHandler(this.CCUiCMCCreateContinuousMFGFromCurveDlg_Load);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
